/**
 * 有特别依赖，但又比较常用的
 */
export default class Tool {
    constructor() {}

    /**
     * 设置触发器
     * @param TriggerClass 具体触发器类
     * @param camCtr 相机控制器
     * @param color  中心颜色
     * @param pos 位置
     * @param onCall 回调函数
     * @returns {*}
     */
    static setTrigger(TriggerClass, camCtr, color, pos, onCall = () => {}) {
        let trg = new TriggerClass({
            size: 1,
            opacity: 0.8,
            color: color,
        });
        trg.position.copy(pos);
        trg.play = 0.002;
        trg.camCtr = camCtr;
        let sp = 0.002;
        let si = 1;
        trg.onHover = (bool) => {
            if (bool) {
                sp = 0.004;
                trg.speed = sp * si;
            } else {
                sp = 0.002;
                trg.speed = sp * si;
            }
        };
        trg.onPress = (bool) => {
            if (bool) {
                si = -1;
                trg.speed = sp * si;
                trg.radius = 0.8;
            } else {
                si = 1;
                trg.speed = sp * si;
                trg.radius = 1;
            }
        };
        trg.onClick = () => {
            onCall();
        };
        return trg;
    }

    /**
     * 触发单个触发器
     * @param trg
     * @param bool
     */
    static triggerOn(trg, bool) {
        if (bool) {
            trg.visible = true;
            trg.play = 0.003;
        } else {
            trg.play = null;
            trg.visible = false;
        }
    }

    /**
     * 触发多个触发器
     * @param triggersObj
     * @param triggers
     */
    static triggersOn(triggersObj, ...triggers) {
        for (let key in triggersObj) {
            let trg = triggersObj['' + key + ''];
            let bool = triggers.findIndex((t) => t.uuid === trg.uuid) !== -1;
            Tool.triggerOn(trg, bool);
        }
    }
}